package com.heima.reggie.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.reggie.common.R;
import com.heima.reggie.pojo.Orders;
import com.heima.reggie.service.OrdersService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
@Autowired
    private OrdersService ordersService;
    @PostMapping("/submit")
    public R submit(@RequestBody  Orders orders){
        log.info("数据内容---------------------------------------------------->{}",orders);
        ordersService.submit2(orders);

        return R.success("chengg");
    }

@GetMapping("/userPage")
    public R userPage(int page,int pageSize){
    Page<Orders> page2 = new Page<>(page,pageSize);
   ordersService.page(page2);

    return R.success(page2);
    }
@GetMapping("/page")
    public R page(int page, int pageSize, String number , String beginTime, LocalDateTime endTime){
    System.out.println(beginTime+"-----------------------------------------------------");
    System.out.println(endTime);
    System.out.println(number);

        Page<Orders> ordersPage = new Page<>(page,pageSize);
    LambdaQueryWrapper<Orders> ordersLambdaQueryWrapper = new LambdaQueryWrapper<>();
    ordersLambdaQueryWrapper.eq(number!=null,Orders::getId,number);
ordersService.page(ordersPage,ordersLambdaQueryWrapper);



    return R.success(ordersPage);
    }

}
